<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%
	String fflag = request.getParameter("fflag");
	String tabNm = request.getParameter("tabNm");
 %>

<script type="text/javascript">
	
	$(function () {
		 $(".upfiles").each(function(){
			 var pkId=$(this).attr("pkId");
			 var fflag=$(this).attr("fflag");
			 if(pkId!=''){
				 setfiles($(this).attr("id"),pkId,fflag);
			 }
	       
	    });
	   
	    //grid.setHeight(100);
	});
	function setfiles(id,pkId,fflag){
		
		var data={pkId:pkId,tabNm:'<%=tabNm %>'};
		 $.ajax({
				type: 'get',
				dataType:'json',
				data:data,
				url: '<%=path%>/system/sysulfilesrec/initList.do',
				success:function(list){
					if(list!=null&&list!=''){
						var h="";
						for(var i=0;i<list.rows.length;i++){
							
							h+='<a href="javascript:uploadFileByUrl(';
			                h+="'"+list.rows[i].filePath+"'";
			                h+=",'"+list.rows[i].fileNm+"'";
			                h+=')">'+list.rows[i].fileNm+'</a>';
			                
				            //添加删除
			                if(fflag==1){
			                	h+=' | <a  href="javascript:uploadFileDeleteRow(';
				                h+="'"+list.rows[i].id+"'";
				                h+=",'"+id+"'";
				                h+=",'"+pkId+"'";
				                
				                h+=')"><i class="sqBtnIco_7"></i>删除</a>'  
				            }
			                h+='<br>';
						}
						 $("#"+id).html(h);
			            
					}
				}
			});
	}
	function getUlFileRecDelColumn(){
		return {	
			        isSort: false,
			        minWidth: 100,
			        render: function (rowdata, rowindex, value){
			        	if(rowdata.audStsCd=="1"){//验证通过不能删除
			        		return "";
			        	}
			            var h='<a class="sq-button-hasicon" href="javascript:uploadFileDeleteRow(';
			                h+="'"+rowdata.id+"'";
			                h+=",'ligergrid_bankacc'"
			                h+=')"><i class="sqBtnIco_7"></i>删除</a>'
			            return h;
			        }
				};
	}
	function uploadFileByUrl(_url,_name){
		if(SQ.regs.img.test(_name)){
			//SQ.imgPreview(_url);
         window.__ImgSrc = _url;
         window.__ImgTit = _name;
         window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', _name, 'location=yes, width=800, height=600');
		}else{
	        window.open(_url);
		}
    }

    function downloadFileByUrl() {
        var data = fileGrid.getData();
//        var files = [];
		var ids = [];
		for (var i = 0; i < data.length; i++) {
		    var map = {};
//		    map.name = data[i].fileNm;
//		    map.path = data[i].filePath.substring(data[i].filePath.indexOf("attachments"));
//		    files.push(map);
            ids.push(data[i].id);
		}
		var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do';
    	var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }
	
	function uploadFileDeleteRow(id,dataId,pkId){
		if(!id){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
			return;
		}
		$.ligerDialog.confirm('确定删除吗?', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{id:id},
				url: '<%=path%>/system/sysulfilesrec/removeById.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 //fileGrid.reload();
						 
						 setfiles(dataId,pkId,1);
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	
	
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//刷新附件列表
	function refreshUlFileRecList(){
		fileGrid.reload();
	}
	//刷新附件列表:重新设置
	function refreshUlFileRecListByPkId(_pkId,_tabNm){
		fileGrid.setParm("pkId",_pkId);
		fileGrid.setParm("tabNm",_tabNm);
		fileGrid.reload();
	}
	
</script>
